<?php

function reequipment_adminapi_deletemaintenance($args)
{
    // Get arguments from argument array
    extract($args);
    // Argument check
    if (!isset($maintenance_id)) {
        $msg = xarML('Invalid Parameter Count');
        xarErrorSet(XAR_SYSTEM_EXCEPTION, 'BAD_PARAM', new SystemException($msg));
        return;
    }

    // Get datbase setup
    $dbconn =& xarDBGetConn();
    $xartable =& xarDBGetTables();
    $table = $xartable['remaintenance'];

	// Only allowing open maintenance to be deleted.
    // Delete the item
    $query = "DELETE FROM $table
              WHERE maintenance_id = ? AND date_complete = 0";
    $bindvars = array($maintenance_id);
    $result =& $dbconn->Execute($query,$bindvars);
    if (!$result) return;
    // Let any hooks know that we have deleted a link
    $args['module'] = 'reequipment';
    $args['itemtype'] = 6; //tag
    $args['itemid'] = $maintenance_id;
    xarModCallHooks('item', 'delete', $maintenance_id, $args);
    
    // Need to delete the cycle relationship.
    $cycles = xarModAPIFunc('reequipment', 'admin', 'deleterelcycles', array('maintenance_id' => $maintenance_id));
    
    // Let the calling process know that we have finished successfully
    return true;
}
?>